package com.tanhua.server.controller;

import com.tanhua.server.service.IMService;
import com.tanhua.server.utils.NoAuthorization;
import com.tanhua.server.vo.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * [消息] 模块
 */
@RestController
@RequestMapping("messages")
public class IMController {

    @Autowired
    private IMService imService;

    /**
     * 添加联系人
     */
    @PostMapping("contacts")
    public ResponseEntity<Void> contactUser(@RequestBody Map<String, Object> param) {
        Long friendId = Long.valueOf(param.get("userId").toString());
        this.imService.contactUser(friendId);
        return ResponseEntity.ok(null);
    }

    /**
     * 查询联系人列表
     */
    @GetMapping("contacts")
    public ResponseEntity<PageResult> queryContactsList(@RequestParam(value = "page", defaultValue = "1") Integer page,
                                                        @RequestParam(value = "pagesize", defaultValue = "10") Integer pagesize,
                                                        @RequestParam(value = "keyword", required = false) String keyword) {
        PageResult pageResult = this.imService.queryContactsList(page, pagesize, keyword);
        return ResponseEntity.ok(pageResult);
    }

    /**
     * 查询点赞列表
     */
    @GetMapping("likes")
    public ResponseEntity<PageResult> queryMessageLikeList(@RequestParam(value = "page", defaultValue = "1") Integer page,
                                                           @RequestParam(value = "pagesize", defaultValue = "10") Integer pageSize) {
        PageResult pageResult = this.imService.queryMessageLikeList(page, pageSize);
        return ResponseEntity.ok(pageResult);
    }

    /**
     * 查询评论列表
     */
    @GetMapping("comments")
    public ResponseEntity<PageResult> queryMessageCommentList(@RequestParam(value = "page", defaultValue = "1") Integer page,
                                                              @RequestParam(value = "pagesize", defaultValue = "10") Integer pageSize) {
        PageResult pageResult = this.imService.queryMessageCommentList(page, pageSize);
        return ResponseEntity.ok(pageResult);
    }

    /**
     * 查询喜欢列表
     */
    @GetMapping("loves")
    public ResponseEntity<PageResult> queryMessageLoveList(@RequestParam(value = "page", defaultValue = "1") Integer page,
                                                           @RequestParam(value = "pagesize", defaultValue = "10") Integer size) {
        PageResult pageResult = this.imService.queryMessageLoveList(page, size);
        return ResponseEntity.ok(pageResult);
    }

    /**
     * 查询公告列表
     */
    @GetMapping("announcements")
    @NoAuthorization
    public ResponseEntity<PageResult> queryMessageAnnouncementList(@RequestParam(value = "page", defaultValue = "1") Integer page,
                                                                   @RequestParam(value = "pagesize", defaultValue = "10") Integer size) {
        PageResult pageResult = this.imService.queryMessageAnnouncementList(page, size);
        return ResponseEntity.ok(pageResult);
    }

}
